import React from 'react';

import { getAuthEmail } from '@/entities/auth/model/selectors';
import { productApi } from '@/entities/course';
import { useAppSelector } from '@/shared/store';
import dayjs from 'dayjs';
import { useRouter } from 'next/router';

import cs from './Purchase.module.scss';

export const Purchase = () => {
  const email = useAppSelector(getAuthEmail);
  const router = useRouter();
  const { id } = router.query;
  const { data: order } = productApi.useGetSingleOrderQuery(id as string, { skip: !id });
  return (
    <div className={cs.block}>
      <span className={cs.title}>О покупке</span>
      <div className={cs.data}>{dayjs(order?.createdAt as string).format('D MMMM YYYY в HH:mm')}</div>
      <span className={cs.check}>
        Чек был выслан на почту <br></br>
        {order?.email || localStorage.getItem('authEmail') || email}
      </span>
    </div>
  );
};
